package com.qyhl.module_home.city.bestone.ontype;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.view.View;

import com.qyhl.module_home.R;
import com.qyhl.webtv.commonlib.entity.home.BestoneItemTypeBean;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.List;

public class AlllistAdapter extends CommonAdapter<BestoneItemTypeBean> {
    private Activity context;

    private View.OnClickListener onClickListener = v -> toCall((String) v.getTag());

    public AlllistAdapter(Activity context, List<BestoneItemTypeBean> datas) {
        super(context, R.layout.home_bestone_all, datas);
        this.context = context;
    }

    @Override
    protected void convert(ViewHolder viewHolder, BestoneItemTypeBean bean, int positon) {
        viewHolder.setText(R.id.searchTitle, bean.getTitle());
        viewHolder.setText(R.id.searchPhone, bean.getPhone());
        viewHolder.getView(R.id.gocall).setTag(bean.getPhone());
        viewHolder.getView(R.id.gocall).setOnClickListener(onClickListener);
    }


    //手动拨打电话，无需权限
    private void toCall(String phoneNum) {
        Intent intent = new Intent(Intent.ACTION_DIAL);
        Uri data = Uri.parse("tel:" + phoneNum);
        intent.setData(data);
        context.startActivity(intent);
    }
}

